﻿using HomeCareLibrary.AppService.Mappers;
using HomeCareLibrary.Core.DataContracts;
using HomeCareLibrary.Core.Dtos;
using HomeCareLibrary.DataAccess;
using HomeCareLibrary.Repository;
using System.Linq;

namespace HomeCareLibrary.AppService
{
    public class AppRefreshAppService : AppServiceBase
    {
        public CTMoReminderRefreshResultDto CheckMonthlyReminderRefresh(MonthlyReminderRefreshRequest request)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var repository = new Repository<CTMoReminderRefreshResult>(unitOfWork);
                var queryParameter = string.Format("@userId={0}, @moAlertWeek={1}, @moAlertDay={2}, @moAlertHour={3}, @moAlertBadge={4}, @moAlertPopup={5}", request.UserId, request.AppMoAlertWeek, request.AppMoAlertDay, request.AppMoAlertHour, request.AppMoAlertBadge, request.AppMoAlertPopup);
                var data = repository.ExecuteFuntion("[sp_App_MoReminder_Refresh]", queryParameter).ToDTOs();
                return data.FirstOrDefault();
            }
        }

        public CTPromoCodeRefreshResultDto CheckPromocodeRefresh(PromoCodeRefreshRequest request)
        {
            using (var unitOfWork = new UnitOfWork())
            {
                var repository = new Repository<CTPromoCodeRefreshResult>(unitOfWork);
                var queryParameter = string.Format("@paramUserId={0}, @paramPromoCode='{1}'", request.UserId, request.PromoCode.Replace("'", "''"));
                var data = repository.ExecuteFuntion("[sp_App_PromoCode_Refresh]", queryParameter).ToDTOs();
                return data.FirstOrDefault();
            }
        }
    }
}
